/*
 * CopyRight (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
 */
package com.huawei.bdsolution.loadsmetric.dto;

import lombok.Data;

import java.beans.ConstructorProperties;

import static com.huawei.bdsolution.loadsmetric.util.MultiLoadResourceUsageSortPolicy.CUSTOM_SORT_ORDER_NAMES_NUM;

@Data
public class LoadsRecordAverage {
    private String hostName;
    private Float avgCpuUsage;
    private Float avgMemUsage;
    private Float avgDiskIoUsage;
    private Float avgNetIoUsage;
    private Float weightedUsage;
    private String timeStamp;

    private int memUsageLevel = -1;
    private int vcoresUsageLevel = -1;

    private String overLoadType = "-1";

    private int[] customSortOrderValues = new int[CUSTOM_SORT_ORDER_NAMES_NUM];

    @ConstructorProperties({"host_name","avg_cpu_usage","avg_mem_usage","avg_disk_io_usage","avg_net_io_usage"})
    public LoadsRecordAverage(String hostName, Float avgCpuUsage, Float avgMemUsage, Float avgDiskIoUsage, Float avgNetIoUsage) {
        this.hostName = hostName;
        this.avgCpuUsage = avgCpuUsage;
        this.avgMemUsage = avgMemUsage;
        this.avgDiskIoUsage = avgDiskIoUsage;
        this.avgNetIoUsage = avgNetIoUsage;
    }

    public String getHostName() {
        return hostName;
    }

    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    public Float getAvgCpuUsage() {
        return avgCpuUsage;
    }

    public void setAvgCpuUsage(Float avgCpuUsage) {
        this.avgCpuUsage = avgCpuUsage;
    }

    public Float getAvgMemUsage() {
        return avgMemUsage;
    }

    public void setAvgMemUsage(Float avgMemUsage) {
        this.avgMemUsage = avgMemUsage;
    }

    public Float getAvgDiskIoUsage() {
        return avgDiskIoUsage;
    }

    public void setAvgDiskIoUsage(Float avgDiskIoUsage) {
        this.avgDiskIoUsage = avgDiskIoUsage;
    }

    public Float getAvgNetIoUsage() {
        return avgNetIoUsage;
    }

    public void setAvgNetIoUsage(Float avgNetIoUsage) {
        this.avgNetIoUsage = avgNetIoUsage;
    }

    public Float getWeightedUsage() {
        return weightedUsage;
    }

    public void setWeightedUsage(Float weightedUsage) {
        this.weightedUsage = weightedUsage;
    }

    public String getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }

    public int getMemUsageLevel() {
        return memUsageLevel;
    }

    public void setMemUsageLevel(int memUsageLevel) {
        this.memUsageLevel = memUsageLevel;
    }

    public int getVcoresUsageLevel() {
        return vcoresUsageLevel;
    }

    public void setVcoresUsageLevel(int vcoresUsageLevel) {
        this.vcoresUsageLevel = vcoresUsageLevel;
    }

    public String getOverLoadType() {
        return overLoadType;
    }

    public String getFormatOverLoadType() {
        switch (overLoadType) {
            case "0":
                return "cpu";
            case "1":
                return "mem";
            case "2":
                return "disk_io";
            case "3":
                return "net_io";
        }
        return "";
    }

    public void setOverLoadType(String overLoadType) {
        this.overLoadType = overLoadType;
    }

    public int[] getCustomSortOrderValues() {
        return customSortOrderValues;
    }

    public void setCustomSortOrderValues(String[] customSortOrderNames) {
        for (int i = 0; i < Math.min(customSortOrderNames.length, customSortOrderValues.length); i++) {
            customSortOrderValues[i] = getSortInfoValue(customSortOrderNames[i]);
        }
    }

    public int getSortInfoValue(String sortOrderName) {
        switch (sortOrderName) {
            case "mem_level":
                return memUsageLevel;
            case "vcores_level":
                return vcoresUsageLevel;
            case "weighted":
                return (int) (weightedUsage * 100);
        }
        return 0;
    }

    public Object getSortInfoOriginalValue(String sortOrderName) {
        switch (sortOrderName) {
            case "mem_level":
                return memUsageLevel;
            case "vcores_level":
                return vcoresUsageLevel;
            case "weighted":
                return weightedUsage;
        }
        return 0;
    }
}
